<?php

require_once 'common/conn.php';
require_once 'common/common.php';

$resultArray = array();

if (isset($_GET['month']) && isset($_GET['usercode']) && isset($_GET['start']) && isset($_GET['limit'])) {
    $start = $_GET['start'];
    $limit = $_GET['limit'];
    $month = trim($_GET['month']);
    $usercode = trim($_GET['usercode']);
    if (is_numeric($start) && is_numeric($limit)) {
        $db = new DBC();
        $sql = "SELECT DISTINCT m.flashcode AS code,m.name,m.url,m.version,m.price,m.goodprice,m.promotion,m.imageURL,m.type1 AS type,"
                . "(SELECT COUNT(flashcode) FROM t_device_product p WHERE p.usercode = '" . $usercode
                . "' AND p.type = 4 AND p.flashcode = m.flashcode) AS isDownload FROM t_music m "
                . " WHERE m.status = 1 AND m.month = " . $month . " ORDER BY m.num LIMIT " . $start . "," . $limit;
        $data = $db->fetchData($sql);        
        if (checkArrayNotEmpty($data)) {
            $result['errorNo'] = "0";
            $result['errorMsg'] = "";
            for ($i = 0; $i < count($data); $i++) {
                if (!isNull($data[$i]['isDownload']) && $data[$i]['isDownload'] > 0) {
                    $data[$i]['isDownload'] = "1";
                } else {
                    $data[$i]['isDownload'] = "0";
                }
            }
        }
    }
} else {
    $resultArray['errorNo'] = "1";
    $resultArray['errorMsg'] = "提交参数不完整";
}
echo json_encode($data);
?>